﻿@{
    ViewBag.Title = "登录 - 百家衣(www.360baijiayi.com)";
    ViewBag.Description = "百家衣(www.360baijiayi.com)是一个专注婴儿闲置衣物买卖的网站，在这里妈妈们可以在线买卖宝宝闲置的衣服、玩具。“百家衣”是婴儿服的一种，由一百个家庭收集到布片做成，故名“百家衣”";
    ViewBag.KeyWords = "百家衣,买卖,旧衣服,二手,二手衣服,闲置,宝宝,婴儿,儿童,孩子,衣服,小孩衣服,婴儿衣服,寄售,玩具,同城置换,同城交易,四川二手,成都二手衣服";
    Layout = "~/Views/Shared/_Layout_Nested.cshtml";
    ResourceHelper.RegisterCss(this, "account.css");
}
@section Js_InHeader{
    @Content.Script("jquery.form.js",Url)
}

<div class="mainblock">
   <div class="mainblock whiteblock">
      <div class="reg_title line-height40"><span class="font-size20 green-font font-weight4">用户登录</span></div>

      <div class="reg_content">
        <div class="reg_left_outer fl">
            <form id="login_form" action="@Url.Action("AjaxLogin","Account")" method="post">
                <p>
                  <label>用户名：</label>
                  <input type="text" id="username" name="username" class="input_box" />
                </p>
                <p>
                  <label>密码：</label>
                  <input type="password" id="password" name="password" class="input_box" />
                </p> 
                <p>
                  <input type="submit" class="button-green register_submit button_pointer" id="login_btn" value="登录" />
                </p>
                <div class="clear"></div>
            </form>
        </div>
        <div class="reg_right_outer fr font-size13">
            <span>没有账号？请马上注册</span>
            <a href="@Url.Action("Register","Account")" class="button-green login_link button_pointer">马上注册</a>
            @Html.Partial("_OAuth_Partial")
        </div>
        <div class="clear"></div>
      </div>

    </div>
</div>
 @Content.Css("fancybox/jquery.fancybox-1.3.4.css", Url, BabyPlan.mvcApp.Infras.SourceRootEnums.JsLib)  
<style type="text/css">
#fancybox-left, #fancybox-right {
	width: 20%;
}
</style>
@Content.Script("fancybox/jquery.fancybox-1.3.4.js", Url)
@Content.Script("fancybox.msgbox.js", Url)
<script type="text/javascript">
    (function () {
        var options = {
            dataType: 'json',
            beforeSubmit: beforeSubmit,
            success: submitSuccess
        };
        //$("#login_form").ajaxForm(options);

        function queryString(key) {
            return (document.location.search.match(new RegExp("(?:^\\?|&)" + key + "=(.*?)(?=&|$)")) || ['', null])[1];
        }

        function beforeSubmit() {
            var userChk = UserNameChk();
            var pwChk = PasswordChk();
            if (!userChk.pass) {
                userChk.elt.focus();
                return false;
            }
            if (!pwChk.pass) {
                pwChk.elt.focus();
                return false;
            }
            $("#login_btn").val("登录中...").attr("disabled", "false");
            return true;
        }

        function submitSuccess(response) {
            if (response.Error == 0) {
                var timeout = 0;
                if (response.ExMessage) {
                    $.showMsg(response.ExMessage, "success");
                    timeout = 2000;
                }
                setTimeout(function () {
                    var returnUrl = queryString("ReturnUrl");
                    if (returnUrl) {
                        window.location = decodeURIComponent(returnUrl);
                    }
                    else
                        window.location = '@Url.Action("Index","User")';
                }, timeout);
            } else {
                $("#login_btn").val("登录").attr("disabled", "");
                $.showMsg(response.ExMessage || response.ErrorMessage, "error");
            }
        }

        function UserNameChk() {
            var me = $("#username");
            var val = me.val();
            if (val.length >= 4 && val.length <= 16) {
                me.css("border", "solid 2px #8CBF26");
                return { pass: true, elt: me };
            }
            else {
                me.css("border", "solid 2px #f00");
                return { pass: false, elt: me };
            }
        }

        function PasswordChk() {
            var me = $("#password");
            var val = me.val();
            if (val.length >= 6 && val.length <= 18) {
                me.css("border", "solid 2px #8CBF26 ");
                return { pass: true, elt: me };
            }
            else {
                me.css("border", "solid 2px #f00");
                return { pass: false, elt: me };
            }
        }

        //添加验证
        $("#username").bind("blur", UserNameChk);
        $("#password").bind("blur", PasswordChk);

        $("#login_form").submit(function () {
            if (beforeSubmit()) {
                var form = $(this);
                $.post(form.attr("action"),
                        form.serialize(),
                        function (data) {
                            submitSuccess(data);
                        }, "json");
            }
            return false;
        });
    })();
</script>


